package com.esteel.settlement.pa.service;

import java.util.Map;

import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;

import com.esteel.settlement.config.pa.ProcesserInfo;
import com.esteel.settlement.pa.packet.Answer;
import com.esteel.settlement.pa.packet.PaPacket;

/**
 * 银行操作指令业务处理接口
 * @author zhangxiuzhi
 *
 * @param <P> 报文
 * @param <T> 返回报文
 */
public abstract class PacketProcesser<P extends PaPacket,T extends Answer> implements BeanNameAware{

	@Autowired
	private Map<String,ProcesserInfo> processer;
	
	/**
	 * 业务执行方法
	 * @param packet
	 * @return
	 */
	public  abstract T execute(P packet);
	
	
	/**
	 *  获得BeanName 以方便获得参数
	 */
	public void setBeanName(String name){
		ProcesserInfo info = new ProcesserInfo();
		info.setTranFunc(getTranFunc());
		info.setBeanClass(this.getClass());
		info.setBeanName(name);
		
		processer.put(getTranFunc(), info);
	}
	
	/**
	 * 返回业务处理方法的交易类型
	 * @return
	 */
	protected abstract  String getTranFunc();
}
